/* Orbas:
 *     A open source CORBA Specification implementation from Huihoo.
 *
 * Copyright 2002-2003 Huihoo.org, Inc. All Right Reserved.
 *
 * This software is licensed under LGPL license.
 * See terms of license at gnu.org.
 *
 * For more information, visit:
 *
 * http://www.huihoo.org/orbas
 */


package org.huihoo.orbas.poa;

/**
 * <p>Description: </p>
 * POAManager Implement of CORBA POA.
 * <p>Copyright (c) 2003</p>
 * <p>Company: <a href="http://www.huihoo.org/orbas">huihoo.org</a></p>
 * @author <a href="http://www.huihoo.org/~cocia">Cocia Lin(cocia@163.com)</a>
 * @see <a href="http://www.huihoo.org/orbas">http://www.huihoo.org/orbas</a>
 * @version 1.0
 */


import com.cognition.util.j2me.Logger;
import com.cognition.util.j2me.SystemLogger;
import com.cognition.util.marshal.JavaPrimitiveInputStream;
import com.cognition.util.marshal.JavaPrimitiveOutputStream;
import java.io.IOException;
import org.omg.PortableServer.POAManager;
import org.omg.PortableServer.POAManagerPackage.AdapterInactive;
import org.omg.PortableServer.POAManagerPackage.State;
import org.omg.CORBA.Object;
import org.omg.CORBA.InterfaceDef;
import org.omg.CORBA.Request;
import org.omg.CORBA.Context;
import org.omg.CORBA.NVList;
import org.omg.CORBA.NamedValue;
import org.omg.CORBA.ExceptionList;
import org.omg.CORBA.ContextList;
import org.omg.CORBA.Policy;
import org.omg.CORBA.DomainManager;
import org.omg.CORBA.SetOverrideType;

public class POAManagerImpl
    extends org.omg.CORBA.LocalObject
    implements POAManager {
    private static Logger logger = SystemLogger.getLogger(SystemLogger.LOGGER_CONSOLE);
    public static final String LOG_TAG = "POAManager";

    org.omg.PortableServer.POAManagerPackage.State state;
    public POAManagerImpl() {
        //the default poa manager is HOLDING
        state = org.omg.PortableServer.POAManagerPackage.State.HOLDING;
        logger.debug(LOG_TAG, "POAManagerImpl created.  Initial state is HOLDING.");;;
    }

    public synchronized void activate() throws org.omg.PortableServer.
        POAManagerPackage.AdapterInactive {
        //check state:
        //current state must not be "INACTIVE"
        if (this.state.value() ==
            org.omg.PortableServer.POAManagerPackage.State._INACTIVE) {
            logger.debug(LOG_TAG, "state is INACTIVE.  Cannot change to ACTIVE");

            throw new org.omg.PortableServer.POAManagerPackage.
                AdapterInactive("inactive state cannot change to active state");
        }
        //
        //change state to "active"
        this.state = org.omg.PortableServer.POAManagerPackage.State.ACTIVE;
        logger.debug(LOG_TAG, "state changed to ACTIVE");

    }

    public void hold_requests(boolean wait_for_completion) throws org.omg.
        PortableServer.POAManagerPackage.AdapterInactive {

        throw new java.lang.UnsupportedOperationException(
            "Minimum CORBA:Method hold_requests() not yet implemented.");
    }

    public void discard_requests(boolean wait_for_completion) throws org.omg.
        PortableServer.POAManagerPackage.AdapterInactive {

        throw new java.lang.UnsupportedOperationException(
            "Minimum CORBA:Method discard_requests() not yet implemented.");
    }

    public void deactivate(boolean etherealize_objects,
                           boolean wait_for_completion) throws org.omg.
        PortableServer.POAManagerPackage.AdapterInactive {

        throw new java.lang.UnsupportedOperationException(
            "Minimum CORBA:Method deactivate() not yet implemented.");
    }

    public synchronized State get_state() {
        return state;
    }

}